//
//  ComparisonTableHeader.m
//  SecondPage
//
//  Created by winston on 13-4-16.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "ComparisonTableHeader.h"

@implementation ComparisonTableHeader

@synthesize sectionIndex;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
//        [self setBackgroundColor:[UIColor whiteColor]];

        groupTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 200, 40)];
        groupTitle.backgroundColor = [UIColor clearColor];
        groupTitle.textAlignment = NSTextAlignmentLeft;
        groupTitle.textColor = [UIColor blackColor];
        groupTitle.font = [UIFont fontWithName:@"Arial" size:18];
        [self addSubview:groupTitle];
        [groupTitle release];
        
        expendBtn = [[UIButton alloc]initWithFrame:CGRectMake(150, 5, 50, 30)];
        [expendBtn addTarget:self action:@selector(onExpend:) forControlEvents:UIControlEventTouchUpInside];
        [expendBtn setImage:[UIImage imageNamed:@"AllAuto_Comparison_Image_Fold"] forState:UIControlStateNormal];
        [self addSubview:expendBtn];
        [expendBtn release];
        
        isExpend = TRUE;
    }
    return self;
}

-(void)onExpend:(id)sender
{
    isExpend = !isExpend;
    
    if (isExpend) {
        [expendBtn setImage:[UIImage imageNamed:@"AllAuto_Comparison_Image_Fold"] forState:UIControlStateNormal];
    }
    else
    {
        [expendBtn setImage:[UIImage imageNamed:@"AllAuto_Comparison_Image_Expansion"] forState:UIControlStateNormal];
    }
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"Notification_Section_Expend" object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:sectionIndex],@"section",[NSNumber numberWithBool:isExpend],@"isexpend", nil]];
    
}

-(void)loadData:(ComparisonGroup*)data
{
    isExpend = data.isExpend;
    if (isExpend) {
        [expendBtn setImage:[UIImage imageNamed:@"AllAuto_Comparison_Image_Fold"] forState:UIControlStateNormal];
    }
    else
    {
        [expendBtn setImage:[UIImage imageNamed:@"AllAuto_Comparison_Image_Expansion"] forState:UIControlStateNormal];
    }
    [groupTitle setText:data.groupTitle];
}

@end
